import request from '@/utils/request'

// 获取文章详情数据
export function getArticleDetail (id) {
  return request({
    url: 'articles/' + id
  })
}

// 关注作者或取消关注
export function fllowAuthor (authorID, isFllow) {
  if (isFllow) {
    return request({
      url: 'user/followings',
      method: 'POST',
      data: {
        target: authorID
      }
    })
  } else {
    return request({
      url: 'user/followings/' + authorID,
      method: 'DELETE'
    })
  }
}

// 获取文章的评价
export function getArticleCommentsByID (artID, offset) {
  return request({
    url: 'comments',
    // params 是get请求带的参数，  data是post请求带的参数
    params: {
      type: 'a',
      source: artID,
      offset
    }
  })
}

// 点赞及其取消点赞
export function likeArticle (articleID, isLike) {
  if (isLike) {
    return request({
      url: 'article/likings',
      method: 'post',
      data: { target: articleID }
    })
  } else {
    return request({
      url: 'article/likings/' + articleID,
      method: 'delete'
    })
  }
}

// 收藏或者取消收藏
export function collectArticle (articleID, isLike) {
  if (isLike) {
    return request({
      url: 'article/collections',
      method: 'post',
      data: { target: articleID }
    })
  } else {
    return request({
      url: 'article/collections/' + articleID,
      method: 'delete'
    })
  }
}

// 获取评论的评论列表、
export function getCommentsByCommentID (commentID, offset) {
  return request({
    url: 'comments',
    // params 是get请求带的参数，  data是post请求带的参数
    params: {
      type: 'c',
      source: commentID,
      offset
    }
  })
}

// 对文章或者评论进行评论
export function commentArticleOrComment (targetID, content, artID) {
  return request({
    url: 'comments',
    method: 'POST',
    data: {
      target: targetID,
      content,
      art_id: artID
    }
  })
}
